#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;

int main() {
  freopen("photo.in", "r", stdin);
  freopen("photo.out", "w", stdout);
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, k;
  cin >> n >> k;

  priority_queue<pair<int, int>> pq;

  for (int i = 0; i < k; i++) {
    int a, b;

    cin >> a >> b;
    if (a > b) {
      swap(a, b);
    }
    pq.push(make_pair(-b, -a));
  }

  int st = 1, ans = 1;

  while (!pq.empty()) {
    int a, b;

    a = -pq.top().second;
    b = -pq.top().first;
    pq.pop();
    if (st <= a) {
      ans++;
      st = b;
    }
  }
  cout << ans << "\n";
  return 0;
}